﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Elements;
using EQ1.Objects;
using EQ1.Templates;

namespace EQ1.Controls {
  public class Button : Control , IUIElement<Button> {
    public Button ( UIDocument doc , string name )
      : base( doc , name ) {
      this.Style_Checkbox = false;
      this.UseCustomMouseoverColor = false;
      this.UseCustomDisabledColor = false;
      this.UseCustomPressedColor = false;
      this.TextAlignCenter = true;
      this.TextAlignRight = false;
      this.TextAlignVCenter = true;
      this.TextOffsetX = 0;
      this.TextOffsetY = 0;
    }
    public Button ( UIDocument doc )
      : this( doc , "Button" ) {
    }

    #region IUIElement<Button> Members

    public void Validate ( Button val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        Button el = new Button( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( Button val ) {
      this.Style_Checkbox = val.Style_Checkbox;
      this.UseCustomMouseoverColor = val.UseCustomMouseoverColor;
      this.UseCustomDisabledColor = val.UseCustomDisabledColor;
      this.UseCustomPressedColor = val.UseCustomPressedColor;
      this.TextAlignCenter = val.TextAlignCenter;
      this.TextAlignRight = val.TextAlignRight;
      this.TextAlignVCenter = val.TextAlignVCenter;
      this.TextOffsetX = val.TextOffsetX;
      this.TextOffsetY = val.TextOffsetY;

      if( val.RadioGroup != null )
        this.RadioGroup = val.RadioGroup;
      if( val.Text != null )
        this.Text = val.Text;
      if( val.MouseOverColor != null )
        this.MouseOverColor = val.MouseOverColor;
      if( val.PressedColor != null )
        this.PressedColor = val.PressedColor;
      if( val.ButtonDrawTemplate != null )
        this.ButtonDrawTemplate = val.ButtonDrawTemplate;
      if( val.Template != null )
        this.Template = val.Template;
      if( val.SoundPressed != null )
        this.SoundPressed = val.SoundPressed;
      if( val.SoundUp != null )
        this.SoundUp = val.SoundUp;
      if( val.SoundFlyby != null )
        this.SoundFlyby = val.SoundFlyby;
      if( val.DecalOffset != null )
        this.DecalOffset = val.DecalOffset;
      if( val.DecalSize != null )
        this.DecalSize = val.DecalSize;
    }

    #endregion

    public bool Style_Checkbox {
      get {
        return bool.Parse( this.GetElement( "Style_Checkbox" ).InnerText );
      }
      set {
        this.Validate( "Style_Checkbox" , value.ToString() );
      }
    }
    public bool UseCustomMouseoverColor {
      get {
        return bool.Parse( this.GetElement( "UseCustomMouseoverColor" ).InnerText );
      }
      set {
        this.Validate( "UseCustomMouseoverColor" , value.ToString() );
      }
    }
    public bool UseCustomDisabledColor {
      get {
        return bool.Parse( this.GetElement( "UseCustomDisabledColor" ).InnerText );
      }
      set {
        this.Validate( "UseCustomDisabledColor" , value.ToString() );
      }
    }
    public bool UseCustomPressedColor {
      get {
        return bool.Parse( this.GetElement( "UseCustomPressedColor" ).InnerText );
      }
      set {
        this.Validate( "UseCustomPressedColor" , value.ToString() );
      }
    }
    public bool TextAlignCenter {
      get {
        return bool.Parse( this.GetElement( "TextAlignCenter" ).InnerText );
      }
      set {
        this.Validate( "TextAlignCenter" , value.ToString() );
      }
    }
    public bool TextAlignRight {
      get {
        return bool.Parse( this.GetElement( "TextAlignRight" ).InnerText );
      }
      set {
        this.Validate( "TextAlignRight" , value.ToString() );
      }
    }
    public bool TextAlignVCenter {
      get {
        return bool.Parse( this.GetElement( "TextAlignVCenter" ).InnerText );
      }
      set {
        this.Validate( "TextAlignVCenter" , value.ToString() );
      }
    }
    public int TextOffsetX {
      get {
        return int.Parse( this.GetElement( "TextOffsetX" ).InnerText );
      }
      set {
        this.Validate( "TextOffsetX" , value.ToString() );
      }
    }
    public int TextOffsetY {
      get {
        return int.Parse( this.GetElement( "TextOffsetY" ).InnerText );
      }
      set {
        this.Validate( "TextOffsetY" , value.ToString() );
      }
    }

    public string RadioGroup {
      get {
        return this.GetElement( "RadioGroup" ).InnerText;
      }
      set {
        this.Validate( "RadioGroup" , value );
      }
    }
    public new string Text {
      get {
        return this.GetElement( "Text" ).InnerText;
      }
      set {
        this.Validate( "Text" , value );
      }
    }
    public RGB MouseOverColor {
      get {
        return ( RGB ) this.GetElement( "MouseOverColor" );
      }
      set {
        this.MouseOverColor.Validate( value , "MouseOverColor" );
      }
    }
    public RGB PressedColor {
      get {
        return ( RGB ) this.GetElement( "PressedColor" );
      }
      set {
        this.PressedColor.Validate( value , "PressedColor" );
      }
    }
    public ButtonDrawTemplate ButtonDrawTemplate {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "ButtonDrawTemplate" );
      }
      set {
        this.ButtonDrawTemplate.Validate( value , "ButtonDrawTemplate" );
      }
    }
    public string Template {
      get {
        return this.GetElement( "Template" ).InnerText;
      }
      set {
        this.Validate( "Template" , value );
      }
    }
    public string SoundPressed {
      get {
        return this.GetElement( "SoundPressed" ).InnerText;
      }
      set {
        this.Validate( "SoundPressed" , value );
      }
    }
    public string SoundUp {
      get {
        return this.GetElement( "SoundUp" ).InnerText;
      }
      set {
        this.Validate( "SoundUp" , value );
      }
    }
    public string SoundFlyby {
      get {
        return this.GetElement( "SoundFlyby" ).InnerText;
      }
      set {
        this.Validate( "SoundFlyby" , value );
      }
    }
    public UIPoint DecalOffset {
      get {
        return ( UIPoint ) this.GetElement( "DecalOffset" );
      }
      set {
        this.DecalOffset.Validate( value , "MouseOverColor" );
      }
    }
    public UISize DecalSize {
      get {
        return ( UISize ) this.GetElement( "DecalSize" );
      }
      set {
        this.DecalSize.Validate( value , "DecalSize" );
      }
    }
  }
}
